Skip to content

GoogleCloudPlatform/cloud-run-button

Repository files navigation

Cloud Run Button

If you have a public repository, you can add this button to your README.md and let anyone deploy your application to Google Cloud Run with a single click.

Try it out with a "hello, world" Go application (source):

Run on Google Cloud

Demo

Cloud Run Button Demo

Add the Cloud Run Button to Your Repo's README

  1. Copy & paste this markdown:

    [![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://deploy.cloud.run)
    
  2. If the repo contains a Dockerfile, it will be built using the docker build command. If the repo uses Maven for the build and it contains the Jib plugin, then the container image will be built with Jib (Jib Spring Boot Sample). Otherwise, CNCF Buildpacks (i.e. the pack build command) will attempt to build the repo (buildpack samples). Alternatively, you can skip these built-in build methods using the build.skip field (see below) and use a prebuild or postbuild hook to build the container image yourself.

Customizing source repository parameters

  • When no parameters are passed, the referer is used to detect the git repo and branch
  • To specify a git repo, add a git_repo=URL query parameter
  • To specify a git branch, add a revision=BRANCH_NAME query parameter.
  • To run the build in a subdirectory of the repo, add a dir=SUBDIR query parameter.

Customizing deployment parameters

If you include an app.json at the root of your repository, it allows you customize the experience such as defining an alternative service name, or prompting for additional environment variables.

For example, a fully populated app.json file looks like this:

{
    "name": "foo-app",
    "env": {
        "BACKGROUND_COLOR": {
            "description": "specify a css color",
            "value": "#fefefe",
            "required": false
        },
        "TITLE": {
            "description": "title for your site"
        },
        "APP_SECRET": {
            "generator": "secret"
        },
        "ORDERED_ENV": {
            "description": "control the order env variables are prompted",
            "order": 100
        }
    },
    "options": {
        "allow-unauthenticated": false,
        "memory": "512Mi",
        "cpu": "1",
        "port": 80,
        "http2": false,
        "concurrency": 80,
        "max-instances": 10
    },
    "build": {
        "skip": false,
        "buildpacks": {
            "builder": "some/builderimage"
        }
    },
    "hooks": {
        "prebuild": {
            "commands": [
                "./my-custom-prebuild"
            ]
        },
        "postbuild": {
            "commands": [
                "./my-custom-postbuild"
            ]
        },
        "precreate": {
            "commands": [
                "echo 'test'"
            ]
        },
        "postcreate": {
            "commands": [
                "./setup.sh"
            ]
        }
    }
}

Reference:

  • name: (optional, default: repo name, or sub-directory name if specified) Name of the Cloud Run service and the built container image. Not validated for naming restrictions.
  • env: (optional) Prompt user for environment variables.
    • description: (optional) short explanation of what the environment variable does, keep this short to make sure it fits into a line.
    • value: (optional) default value for the variable, should be a string.
    • required, (optional, default: true) indicates if they user must provide a value for this variable.
    • generator, (optional) use a generator for the value, currently only support secret
    • order, (optional) if specified, used to indicate the order in which the variable is prompted to the user. If some variables specify this and some don't, then the unspecified ones are prompted last.
  • options: (optional) Options when deploying the service
    • allow-unauthenticated: (optional, default: true) allow unauthenticated requests
    • memory: (optional) memory for each instance
    • cpu: (optional) cpu for each instance
    • port: (optional) if your application doesn't respect the PORT environment variable provided by Cloud Run, specify the port number it listens on
    • http2: (optional) use http2 for the connection
    • concurrency: (optional) concurrent requests for each instance
    • max-instances: (optional) autoscaling limit (max 1000)
  • build: (optional) Build configuration
    • skip: (optional, default: false) skips the built-in build methods (docker build, Maven Jib, and buildpacks), but still allows for prebuild and postbuild hooks to be run in order to build the container image manually
    • buildpacks: (optional) buildpacks config (Note: Additional Buildpack config can be specified using a project.toml file. See the spec for details.)
      • builder: (optional, default: gcr.io/buildpacks/builder:v1) overrides the buildpack builder image
  • hooks: (optional) Run commands in separate bash shells with the environment variables configured for the application and environment variables GOOGLE_CLOUD_PROJECT (Google Cloud project), GOOGLE_CLOUD_REGION (selected Google Cloud Region), K_SERVICE (Cloud Run service name), IMAGE_URL (container image URL), APP_DIR (application directory). Command outputs are shown as they are executed.
    • prebuild: (optional) Runs the specified commands before running the built-in build methods. Use the IMAGE_URL environment variable to determine the container image name you need to build.
      • commands: (array of strings) The list of commands to run
    • postbuild: (optional) Runs the specified commands after running the built-in build methods. Use the IMAGE_URL environment variable to determine the container image name you need to build.
      • commands: (array of strings) The list of commands to run
    • precreate: (optional) Runs the specified commands before the service has been created
      • commands: (array of strings) The list of commands to run
    • postcreate: (optional) Runs the specified commands after the service has been created; the SERVICE_URL environment variable provides the URL of the deployed Cloud Run service
      • commands: (array of strings) The list of commands to run

Notes

  • Disclaimer: This is not an officially supported Google product.
  • See LICENSE for the licensing information.
  • See Contribution Guidelines on how to contribute.

About

Let anyone deploy your GitHub repos to Google Cloud Run with a single click

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published